#include<iostream>
#include<map>
using namespace std;
map<int, int>mp;
const int N = 1e5 + 10;
int arr[N];
int n;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n;
		mp.clear();
		for (int i = 1; i <= n; i++) {
			cin >> arr[i];
			mp[arr[i]]++;
		}
		int ma = 0;
		for (auto item : mp) {
			ma = max(ma, item.second);
		}
		//cout << "ma==" << ma << endl;
		int ans = 0;
		while (ma < n) {
			ans += min(ma, n - ma) + 1;
			ma += min(ma, n - ma);
		}
		cout << ans << endl;
	}
	return 0;
}
